package com.taobaolite.user;

import cn.dev33.satoken.stp.StpInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ResponseStatusException;

import java.util.ArrayList;
import java.util.List;

/***
 * *暂时废弃*
 * 业务逻辑里已经实现了用户角色验证
 */
@Component
public class StpInterfaceImpl implements StpInterface {
    @Autowired
    UserRepository userRepo;

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        //todo 查找某个id的会话拥有的权限
        return null;
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) { //loginId是会话Id，应该可以直接用userId赋值给它
        User user = userRepo.findById((Long) loginId)
                .orElseThrow(() -> new ResponseStatusException(
                        HttpStatus.NOT_FOUND,
                        "User with ID " +
                                loginId +
                                " does not exist. " +
                                "Please check database."
                ));
        //每个用户暂时只有一个角色
        return List.of(user.getType().toString());
    }
}
